<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>短信群发</title>
		<%include("/common/include.html"){}%>
	</head>
	<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<style type="text/css">
		.text{
			padding-right:0px;
			background:url("${cxt !}/sb/themes/insdep/images/combo_arrow.png") no-repeat scroll right center transparent;
			padding-left: 10px;
			border-radius:3px;
		} 
		#sendMessageStatisticFrom{
			height:auto;
			width:100%;
		}
		#sendMessageStatisticFrom ul li{
			width:230px;
			margin-top:10px;
		}
		#sendMessageStatisticFromEmployee{
			height:auto;
			width:100%;
		}
		#sendMessageStatisticFromEmployee ul li{
			width:230px;
			margin-top:10px;
		}
		select{
			appearance:none;
			-moz-appearance:none;
			-webkit-appearance:none;
			width: 200px; 
			height: 30px; 
			border:1px solid #CCCCCC;
		}
	</style>
	<script type="text/javascript">
		function btnEmployee(ids){
			loadDialog($('#datagrid111'),null, '查询', 'bsendMessage/queryMessageEmployee?ids='+ids);
		};
		function btn(customerids){
			loadDialog($('#datagrid111'),null, '查询', 'bsendMessage/queryMessage?ids='+customerids);
		};
		
		$(document).ready(function () {
			searchFromEmployee();
			searchFrom();
		});
		function qingkong(){
			$("#hybh").textbox("setValue","");
		}
		function qingkongEmployee(){
			$("#hybhEmployee").textbox("setValue","");
		}
		function fasong(ids){
			$.slideMsg("顾客短信已发送", parent.$);
			$("#boutProduct").html("");
			var rows = $('#custom').datagrid('getChecked');
			var hybh = $("#hybh").val();
			for(var i=0;i<rows.length;i++){
				var phone= rows[i].phone;
				var customerids=rows[i].customerids;
				$("#boutProduct").append("<input type='hidden' name='bsendMessageList["+i+"].details' value='"+hybh+"'/>"); 
				$("#boutProduct").append("<input type='hidden' name='bsendMessageList["+i+"].peopleids' value='"+customerids+"'/>"); 
				$("#boutProduct").append("<input type='hidden' name='bsendMessageList["+i+"].position' value='2'/>"); 
				$("#boutProduct").append("<input type='hidden' name='bsendMessageList["+i+"].senddate' value='${date(),dateFormat='yyyy-MM-dd'}' class='easyui-datebox theme-textbox-radius' data-options='editable: false'/>"); 
				
			}
 			var url='/bsendMessage/message';
 			
			var data=$('#messagego').serialize();
			var reData = common_ajax.ajaxFunc(url,data);
		}
		function fasongEmployee(ids){
			$.slideMsg("店员短信已发送", parent.$);
			$("#boutProductEmployee").html("");
			var rows = $('#customEmployee').datagrid('getChecked');
			var email = $("#hybhEmployee").val();
			for(var i=0;i<rows.length;i++){
				var ids= rows[i].ids;
				$("#boutProductEmployee").append("<input type='hidden' name='bsendMessageList["+i+"].details' value='"+email+"'/>"); 
				$("#boutProductEmployee").append("<input type='hidden' name='bsendMessageList["+i+"].peopleids' value='"+ids+"'/>"); 
				$("#boutProductEmployee").append("<input type='hidden' name='bsendMessageList["+i+"].position' value='1'/>"); 
				$("#boutProductEmployee").append("<input type='hidden' name='bsendMessageList["+i+"].senddate' value='${date(),dateFormat='yyyy-MM-dd'}' class='easyui-datebox theme-textbox-radius' data-options='editable: false'/>"); 
			}
 			var url='/bsendMessage/messageEmployee';
			var data=$('#messagegoEmployee').serialize();
			var reData = common_ajax.ajaxFunc(url,data);
		}
		//顾客短信编辑窗口
		function gukewindow(){
			$("#messageModel").html("");
			$("#messageModel").append("<option value=''>全部</option>");
			$('#gukemessage').window('open');
			$.post("bsendMessage/messageModel",{},function(result){
				$.each(result,function(i,modelList){
					$("#messageModel").append("<option value='"+modelList.text+"'>"+modelList.modeltype+"</option>");
				})
			});
		}
		//店员短信编辑窗口
		function dianyuanwindow(){
			$('#dianyuanmessage').window('open');
			$("#messageModelEmployee").html("");
			$("#messageModelEmployee").append("<option value=''>全部</option>");
			$.post("bsendMessage/messageModel",{},function(result){
				$.each(result,function(i,modelList){
					$("#messageModelEmployee").append("<option value='"+modelList.text+"'>"+modelList.modeltype+"</option>");
				})
			});
		}
		function selectmessage(){
			var sex = $("#messageModel").val();
			$("#hybh").textbox("setValue",sex);
		}
		function selectmessageEmployee(){
			var sexEmployee = $("#messageModelEmployee").val();
			$("#hybhEmployee").textbox("setValue",sexEmployee);
		}
	</script>
	<body>
		<form id="messagego">
			<div id="boutProduct" style="display: none;"></div>
		</form>
		<form id="messagegoEmployee">
			<div id="boutProductEmployee" style="display: none;"></div>
		</form>
		<div class="easyui-layout" style="width:100%;height:100%">
			<div style="width:100%;height:100%;" data-options="region:'center'">
				<div class="easyui-tabs" style="width:100%;height:100%">
					<div title="顾客">
						<form id="sendMessageStatisticFrom">
							<ul style="height:auto;padding:10px;">
								<li style="display: inline-block;">
									<span style="display:block;">店面名称：</span>
									<input id="organ" type="text" readonly style="width: 188px; height: 28px;border:1px solid #CCCCCC;" onclick="showMenu(); return false;" class="text" value="${curOrgan.name! }"/>
									<input name="_query.selOrganIds" id="organIds" type="hidden" value="${curOrgan.ids! }">
								</li>
								<li style="display: inline-block;">
									<span>姓名：</span>
									<input name="_query.name" id="name" style="width: 200px; height: 30px;" class="easyui-textbox theme-textbox-radius"/>
								</li>
								<li style="display: inline-block;">
									<span>手机号：</span>
									<input name="_query.phone" id="phone" style="width: 200px; height: 30px;" class="easyui-textbox theme-textbox-radius"/>
								</li>
								<li style="display: inline-block;">
									<span>生日：</span>
									<input name="_query.birthday" id="birthday" style="width: 200px; height: 30px;" class="easyui-datebox theme-textbox-radius"/>
								</li>
								<li style="display: inline-block;">
									<span>性别：</span>
									<select class="easyui-combobox theme-textbox-radius" name="_query.sex" id="sex" style="width: 200px;height: 30px;" >
										<option value="">全部</option>
										<option value="男">男</option>
										<option value="女">女</option>
									</select>
								</li>
								<li style="display: inline-block;">
									<span>连续未到天数：</span>
									<input id="noarrive" style="width: 200px; height: 30px;" class="easyui-textbox theme-textbox-radius"/>
									<input name="_query.noarrive" id="noarriveresult" type="text" style="display:none"/>
								</li>
								<li style="display: inline-block;">
									<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:200px" onclick='searchFrom()'>搜索</a>
								</li>
								<li style="display: inline-block;">
									<a href="#" onclick="gukewindow()" class="easyui-linkbutton" data-options="iconCls:'icon-redo'" style="width:200px">发送短信</a>	
								</li>
							</ul >
						</form>
						<table id="custom" style="width: 100%;height:auto;"></table>	
						<!-- 顾客短信群发 -->
						<div id="gukemessage" class="easyui-window" title="顾客" data-options="collapsible:false,minimizable:false,maximizable:false,closable:true,resizable:true" style="width:750px;height:300px;" data-options="cls:'theme-panel-orange'" closed="true">
							<div class="easyui-layout" data-options="fit:true">
								<div class="easyui-panel" title="短信编辑" style="width: 100%;height:100%;" data-options="footer:'#ft'">
							    	<input id="hybh" name="hybh" class="easyui-textbox" data-options="multiline:true,prompt:'请输入短信内容...'" style="width:100%;height:100%;">
								</div>
							    <div id="ft" style="padding:5px;height:30px;">
							    	<a href="#" onclick="qingkong()" class="easyui-linkbutton" data-options="iconCls:'icon-no'">清空</a>
							        <a href="#" onclick="fasong()" class="easyui-linkbutton" data-options="iconCls:'icon-redo'">发送短信</a>
							        <select class="text" onchange="selectmessage()" id="messageModel" ></select>
							    </div>
							</div>
						</div>
					</div>
					<div title="店员">
						<form id="sendMessageStatisticFromEmployee">
							<ul style="height:auto;margin-top: 10px;margin-left: 10px;">
								<li style="display: inline-block;">
									<span>店面名称：</span>
									<input id="organEmployee" type="text" readonly style="width: 188px; height: 30px;border:1px solid #CCCCCC;" onclick="showMenuEmployee(); return false;" class="text" value="${curOrgan.name! }"/>
									<input name="_query.selOrganIds" id="organIdsEmployee" type="hidden" value="${curOrgan.ids! }">
								</li>
								<li style="display: inline-block;">
									<span>姓名：</span>
									<input name="_query.name" id="name" style="width: 200px; height: 30px;" class="easyui-textbox theme-textbox-radius"/>
								</li>
								<li style="display: inline-block;">
									<span>手机号：</span>
									<input name="_query.phone" id="phone" type="text" style="width: 200px; height: 30px;" class="easyui-textbox theme-textbox-radius"/>
								</li>
								<li style="display: inline-block;">
									<span>生日：</span>
									<input name="_query.birthday" id="birthday" type="text" style="width: 200px; height: 30px;" class="easyui-datebox theme-textbox-radius"/>
								</li>
								<li style="display: inline-block;">
									<span>性别：</span>
									<select class="easyui-combobox theme-textbox-radius" name="_query.sex" id="sex" style="width: 200px; height: 30px;" >
										<option value="">全部</option>
										<option value="男">男</option>
										<option value="女">女</option>
									</select>
								</li>
								<li style="display: inline-block;">
									<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:200px" onclick='searchFromEmployee()'>搜索</a>
								</li>
								<li style="display: inline-block;">
									<a href="#" onclick="dianyuanwindow()" class="easyui-linkbutton" data-options="iconCls:'icon-redo'" style="width:200px">发送短信</a>
								</li>
							</ul >
						</form>
						<p style="height:10px;"></p>
						<table id="customEmployee" style="width:100%;height:auto;"></table>
						<!-- 店员短信群发 -->
						<div id="dianyuanmessage" class="easyui-window" title="店员" data-options="collapsible:false,minimizable:false,maximizable:false,closable:true,resizable:true" style="width:750px;height:300px;" data-options="cls:'theme-panel-orange'" closed="true">
							<div class="easyui-layout" data-options="fit:true">
								<div class="easyui-panel" title="短信编辑" style="width: 100%;height:250px;" data-options="footer:'#ftEmployee'">
									<input id="hybhEmployee" name="hybh" class="easyui-textbox" data-options="multiline:true,prompt:'请输入短信内容...'" style="width:100%;height:170px;">
								</div>
								<div id="ftEmployee" style="padding:5px;height: 30px;">
									<a href="#" onclick="qingkongEmployee()" class="easyui-linkbutton" data-options="iconCls:'icon-no'">清空</a>
									<a href="#" onclick="fasongEmployee()" class="easyui-linkbutton" data-options="iconCls:'icon-redo'">发送短信</a>
									<select class="text" onchange="selectmessageEmployee()" id="messageModelEmployee" ></select>
								</div>
							</div>
						</div> 
					</div>
				</div>
				<div id="menuContent" class="menuContent" style="display: none; position: absolute;z-index: 10;">
					<ul id="organSelectTree" class="ztree" style="margin-top: 0;width: 188px;"></ul>
				</div>
				<div id="menuContentEmployee" class="menuContentEmployee" style="display: none; position: absolute;z-index: 10;">
					<ul id="organSelectTreeEmployee" class="ztree" style="margin-top: 0;width: 188px;"></ul>
				</div>
			</div>
		</div>
		<script src="${cxt !}/sb/js/jquery.form.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
		
			//查看顾客详细信息
			function lookCustomerInfo(ids){
				loadViewDialog('查看顾客详细信息', '${cxt !}/customerInfoStatistic/lookCustomerInfo?ids='+ids);
			}
		
			function searchFromEmployee(){
				var orgainIds = $("#organIdsEmployee").val();
				var address = "${cxt!}/bsendMessage/viewEmployee";
				var $formEmployee = $('#sendMessageStatisticFromEmployee');
				var columnsEmployee = [[
										{field:'choice',checkbox:true },
										{field:'name',title:'姓名',width:100,align:'center'},
										{field:'mobile',title:'手机号',width:120,align:'center'},
										{field:'sex',title:'性别',width:120,align:'center'},
										{field:'personnel_birthday',title:'生日',width:120,align:'center'},
										{field:'gangwei',title:'岗位',width:120,align:'center'},
										{field:'YNContent',title:'操作',width:100,align:'center',
											formatter:function(value,row,index){
													return '<a onclick='+'btnEmployee(\'' + row.ids + '\')'+' class='+'button-edit button-success  l-btn l-btn-small'+'><span class='+'l-btn-left'+'><span  style='+'color:green'+' class='+'l-btn-text'+'>查询</span></span></a>';
											}},
										]]
				initCustomerInfoTableEmployee(orgainIds,address,$formEmployee,columnsEmployee);
			}
			function searchFrom(){
				var noarrive = $("#noarrive").val();
				if(noarrive!=""){
					var a = new Date();
					a = a.valueOf()
					a = a - noarrive * 24 * 60 * 60 * 1000
					a = new Date(a)
					document.getElementById("noarriveresult").value=a.getFullYear() + "-" + (a.getMonth() + 1) + "-" + a.getDate();
				}
				var orgainIds = $("#organIds").val();
				var address = "${cxt!}/bsendMessage/view";
				var $form = $('#sendMessageStatisticFrom');
				var columns = [[
								{field:'choice',checkbox:true },
								{field:'name',title:'姓名',width:100,align:'center',
									formatter: function(value,row,index){
										var ids = row.customerids;
										if(value==null){
											return  row.name=" ";
										}
										else{
											return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
										}
									}
								},
								{field:'hybh',title:'会员编号',width:100,align:'center',sortable:true},
								{field:'registtime',title:'注册时间',width:100,align:'center',sortable:true},
						  		{field:'sex',title:'性别',width:50,align:'center'},
						  		{field:'phone',title:'手机号',width:120,align:'center'},
						  		{field:'birth',title:'生日',width:120,align:'center',sortable:true},
						  		{field:'tostoredate',title:'上次到店日期',width:100,align:'center',sortable:true,hidden:false},
								{field:'weight',title:'进店体重',width:100,align:'center',sortable:true,
									formatter: function(value,row,index){
										if(row.nowweight != null){
											var a=row.nowweight+'斤';
											return  a;
										}
									}},
								{field:'std_weight',title:'标准体重',width:100,align:'center',sortable:true,
									formatter: function(value,row,index){
										if(row.nowweight != null){
											var a=row.nowweight+'斤';
											return  a;
										}
									}},
								{field:'nowweight',title:'现在体重',width:100,align:'center',sortable:true,
									formatter: function(value,row,index){
										if(row.nowweight != null){
											var a=row.nowweight+'斤';
											return  a;
										}
									}},
								{field:'YNContent',title:'操作',width:100,align:'center',
									formatter:function(value,row,index){
											return '<a onclick='+'btn(\'' + row.customerids + '\')'+' class='+'button-edit button-success  l-btn l-btn-small'+'><span class='+'l-btn-left'+'><span  style='+'color:green'+' class='+'l-btn-text'+'>查询</span></span></a>';
									}},
				              ]]
				initCustomerInfoTable(orgainIds,address,$form,columns);
			}
			function initTableTitle(){
				var name = $("#organ").val();
				return name;
			}
			function initCustomerInfoTable(orgainIds,address,$form,columns){
				var name = initTableTitle();
				$('#custom').datagrid({
					title:name,
					cls: "theme-datagrid",
					toolbar: '#tb',
					singleSelect: true,
					rownumbers: true, //显示序号
					pagination: true,
					pageSize: 10,
					url: address,
					queryParams: sy.serializeObject($form),
				    method: 'post',
					collapsible: true,
					remoteSort:false,
					multiSort:true,
					selectOnCheck:$(this).is(':checked'),
					checkOnSelect:$(this).is(':checked'),
					columns: columns,
					onLoadSuccess:function(){
						$('#custom').datagrid("selectRow", 0);
						// 获取主表选中行
					},
					onClickRow:function(rowIndex,rowData){
					}
				});
			}
			function initCustomerInfoTableEmployee(orgainIds,address,$form,columns){
				var name = initTableTitle();
				$('#customEmployee').datagrid({
					title:name,
					cls: "theme-datagrid",
					toolbar: '#tb',
					singleSelect: true,
					rownumbers: true, //显示序号
					pagination: true,
					pageSize: 10,
					url: address,
					queryParams: sy.serializeObject($form),
				    method: 'post',
					collapsible: true,
					remoteSort:false,
					multiSort:true,
					selectOnCheck:$(this).is(':checked'),
					checkOnSelect:$(this).is(':checked'),
					columns: columns,
					onLoadSuccess:function(){
						$('#customEmployee').datagrid("selectRow", 0);
						// 获取主表选中行
					},
					onClickRow:function(rowIndex,rowData){
					}
				});
			}
		</script>
		<!-- 顾客标签门店树形图 -->
		<script type="text/javascript">
			var organIds=$('#organIds').val();
			var setting = {
				async : {
					enable : true,
					url : '${cxt!}/common/getOrgenTree',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					otherParam : {
						"organIds" : organIds
					},
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClick,
					onAsyncSuccess : organTreeOnAsyncSuccess
				}
			};
			var flag=0;//只初始化一次标识
			function organTreeOnAsyncSuccess(event, treeId, msg) {
				if(flag == 0){
					var organTree = $.fn.zTree.getZTreeObj("organSelectTree");
					var nodes = organTree.getNodes();
					flag = 1;
				}
			}
			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organSelectTree");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						if(i == (node.length-1)){
							path += node[i].name;
						}else{
							path += node[i].name + "/";
						}
					}
				}
				var cityObj = $("#organ");
				cityObj.attr("value", path);
				$("#organIds").attr("value", treeNode.id);
				hideMenu();
			}
			function showMenu() {
				var cityObj = $("#organ");
				var cityOffset = $("#organ").offset();
				$("#menuContent").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
					hideMenu();
				}
			}
			$.fn.zTree.init($("#organSelectTree"), setting);
		</script>
		<!-- 店员标签门店树形图 -->
		<script type="text/javascript">
			var organIdsEmployee=$('#organIdsEmployee').val();
			var settingEmployee = {
				async : {
					enable : true,
					url : '${cxt!}/common/getOrgenTree',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					otherParam : {
						"organIds" : organIdsEmployee
					},
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClickEmployee,
					onAsyncSuccess : organTreeOnAsyncSuccessEmployee
				}
			};
			var flagEmployee=0;//只初始化一次标识
			function organTreeOnAsyncSuccessEmployee(event, treeId, msg) {
				if(flagEmployee == 0){
					var organTree = $.fn.zTree.getZTreeObj("kEmployee");
					var nodes = organTree.getNodes();
					flagEmployee = 1;
				}
			}
			function onClickEmployee(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organSelectTreeEmployee");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						if(i == (node.length-1)){
							path += node[i].name;
						}else{
							path += node[i].name + "/";
						}
					}
				}
				var cityObj = $("#organEmployee");
				cityObj.attr("value", path);
				$("#organIdsEmployee").attr("value", treeNode.id);
				hideMenuEmployee();
			}
			function showMenuEmployee() {
				var cityObj = $("#organEmployee");
				var cityOffset = $("#organEmployee").offset();
				$("#menuContentEmployee").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
				$("body").bind("mousedown", onBodyDownEmployee);
			}
			function hideMenuEmployee() {
				$("#menuContentEmployee").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDownEmployee);
			}
			function onBodyDownEmployee(event) {
				if (!(event.target.id == "menuBtn" || event.target.id  == "menuContentEmployee" || $(event.target).parents("#menuContentEmployee").length > 0)){
					hideMenuEmployee();
				}
			}
			$.fn.zTree.init($("#organSelectTreeEmployee"), settingEmployee);
		</script>
	</body>
</html>
